/**
 *
 */
function soapWrapFunc(bdStr){
    // 封装SOAP头尾
    var soapHead = '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://Webservice.zjusc.edu.cn/"><env:Body>', soapTail = '</env:Body></env:Envelope>';
    return soapHead + bdStr + soapTail;
}
var extXml;

function loadBaseInfo(id){
	var dateReg = /\d{4}\-\d{2}\-\d{2}/;
	var str='<web:GetStudentBaseInfoById><id>' + id + '</id></web:GetStudentBaseInfoById>';
	    $.ajax({
        type: "POST",
        contentType: "text/xml",
        url: '../../Service/StudentBaseInfoService',
        data: soapWrapFunc(str),
        dataType: 'xml',
        success: function(xml){
				$.each($(xml).find('item'), function(i, n){
					$('#stubs_name').text($(this).find('stubs_name').text());
					$('#stubs_majorID').val($(this).find('stubs_majorID').text());
					
				});
        },
        beforeSend: function(xhr){
            xhr.setRequestHeader("SOAPAction", "\"\"");
        },
        error: function(x, e){
            alert('error:' + x.responseText);
        },
        complete: function(x){
        
        }
    });
}
var stuext_id;
function loadExtendInfo(id){
		var dateReg = /\d{4}\-\d{2}\-\d{2}/;
	var str='<web:GetStudentExtendInfoById><id>' + id + '</id></web:GetStudentExtendInfoById>';
	    $.ajax({
        type: "POST",
        contentType: "text/xml",
        url: '../../Service/StudentExtendInfoService',
        data: soapWrapFunc(str),
        dataType: 'xml',
        success: function(xml){
				$.each($(xml).find('item'), function(i, n){
					stuext_id=$(this).find('stuext_id').text();
					var examType=$(this).find('stuext_examType').text();
					$('#stuext_examCardID').text($(this).find('stuext_examCardID').text());
					//$('#stuext_examType').val(examType);
					$('#stuext_englishScore').val($(this).find('stuext_englishScore').text());
					$('#stuext_majorScore').val($(this).find('stuext_majorScore').text());
					$('#stuext_complexScore').val($(this).find('stuext_complexScore').text());
					$('#stuext_englishResult').val($(this).find('stuext_englishResult').text());
					$('#stuext_majorResult').val($(this).find('stuext_majorResult').text());
					$('#stuext_practiseResult').val($(this).find('stuext_practiseResult').text());
					$('#stuext_compreResult').val($(this).find('stuext_compreResult').text());
					if (examType == '0') {
						$('#stuext_complexScore').attr('disabled', true);
						$('#stuext_englishScore').attr('disabled', false);
						$('#stuext_majorScore').attr('disabled', false);
						$('#stuext_examType').text("自主考试");
					}
					else if (examType == '1') {
						
						$('#stuext_complexScore').attr('disabled', false);
						$('#stuext_englishScore').attr('disabled', true);
						$('#stuext_majorScore').attr('disabled', true);
						$('#stuext_examType').text("推荐选拔");
					}
					else if (examType == '2') {
						$('#stuext_complexScore').attr('disabled', true);
						$('#stuext_englishScore').attr('disabled', true);
							$('#stuext_majorScore').attr('disabled', true);
							$('#stuext_examType').text("考研调剂");
							}
						
				});
        },
        beforeSend: function(xhr){
            xhr.setRequestHeader("SOAPAction", "\"\"");
        },
        error: function(x, e){
            alert('error:' + x.responseText);
        },
        complete: function(x){
        
        }
    });
}


function addMajorCode(){
	var str='<web:GetAllMajorInfo></web:GetAllMajorInfo>';
	$.ajax({
        type: "POST",
        contentType: "text/xml",
        url: '../../Service/MajorCodeService',
        data: soapWrapFunc(str),
        dataType: 'xml',
		success:function(xml){
			$.each($(xml).find('item'), function(i, n){
				//$("#major").append("<option value="+$(this).find("ma_id").text()+">"+$(this).find("ma_majorName").text()+"</option>"); 
				$("#stubs_majorID").append("<option value="+$(this).find("ma_id").text()+">"+$(this).find("ma_majorName").text()+"</option>"); 
				
				
			});
			
		},
		beforeSend: function(xhr){
            xhr.setRequestHeader("SOAPAction", "\"\"");
        },
        error: function(x, e){
            alert('error:' + x.responseText);
        },
        complete: function(x){
        
        }
	});
}


$(function(){
	/*$.editMode=0;
    loadExamData();*/
	addMajorCode();
	$('#searchButton').click(function(){
		var id=$.trim($('#stnum').val());
		loadBaseInfo(id);
		loadExtendInfo(id);
		
	});
	
	$('#saveButton').click(function(){
		var stuext_englishScore=$.trim($('#stuext_englishScore').val());
		var stuext_majorScore=$.trim($('#stuext_majorScore').val());
		var stuext_complexScore=$.trim($('#stuext_complexScore').val());
		var stuext_englishResult=$.trim($('#stuext_englishResult').val());
		var stuext_majorResult=$.trim($('#stuext_majorResult').val());
		var stuext_practiseResult=$.trim($('#stuext_practiseResult').val());
		var stuext_compreResult=$.trim($('#stuext_compreResult').val());
		var sendBody='<web:ModifyStudentScoreInfo>'+
		'<astuext_id>'+stuext_id+'</astuext_id>'+
		'<astuext_englishScore>'+stuext_englishScore +'</astuext_englishScore>'+
		'<astuext_majorScore>'+stuext_majorScore +'</astuext_majorScore>'+
		'<astuext_complexScore>'+stuext_complexScore +'</astuext_complexScore>'+
		'<astuext_englishResult>'+stuext_englishResult +'</astuext_englishResult>'+
		'<astuext_majorResult>'+stuext_majorResult +'</astuext_majorResult>'+
		'<astuext_practiseResult>'+stuext_practiseResult +'</astuext_practiseResult>'+
		'<astuext_compreResult>'+stuext_compreResult +'</astuext_compreResult>'+
		
		
		'</web:ModifyStudentScoreInfo>';
		    $.ajax({
            type: "POST",
            contentType: "text/xml",
            url: '../../Service/StudentExtendInfoService',
            data: soapWrapFunc(sendBody),
            dataType: 'xml',
            success: function(xml){
                alert($(xml).find('return').text());
            },
            beforeSend: function(xhr){
                xhr.setRequestHeader("SOAPAction", "\"\"");
            },
            error: function(x, e){
                alert('error:' + x.responseText);
            },
            complete: function(x){
            
            }
        });
	});
});


/*
 *
 *
 */
